﻿import sys,os
import zipfile
import cv2  
from PyQt4 import QtGui,QtCore

class resType(QtGui.QWidget):
	def __init__(self,parent=None):   
		super( resType, self ).__init__()

		self.setGeometry(300, 300, 800, 480)
		self.setWindowTitle('ET700')
		self.setWindowIcon(QtGui.QIcon('icons/web.png'))

		self.tag = QtGui.QPushButton(u'制作标签资源', self)
		self.tag.setGeometry(250, 100, 300, 80)
		self.connect(self.tag, QtCore.SIGNAL('clicked()'), self.setTag)
		
		self.active = QtGui.QPushButton(u'制作活动资源', self)
		self.active.setGeometry(250, 300, 300, 80)
		self.connect(self.active, QtCore.SIGNAL('clicked()'), self.setActive)
		
	def setTag(self):
		if self.tag.isChecked():
			print "fail"
		else:
			self.tagWin = tagRes()
			self.tagWin.show()

	def setActive(self):
		if self.active.isChecked():
			print "fail"
		else:
			print "ok"
			

class tagRes(QtGui.QMainWindow):
	def __init__(self,parent=None):  
		super(tagRes, self ).__init__()
		
		self.setGeometry(300, 300, 800, 480)
		self.setWindowTitle(u'标签')
		
		self.textEdit = QtGui.QTextEdit()
		self.setCentralWidget(self.textEdit)
		self.statusBar()
		self.setFocus()
		exit = QtGui.QAction(QtGui.QIcon('icons/open.png'), 'Open', self)
		exit.setShortcut('Ctrl+O')
		exit.setStatusTip('Open new file')
		
		#self.connect(exit, QtCore.SIGNAL('triggered()'), self.showDialog)
		#menubar = self.menuBar()
		#file = menubar.addMenu('&File')
		#file.addAction(exit)
		
		self.tag = QtGui.QPushButton(u'添加标签背景', self)
		self.tag.setGeometry(250, 50, 300, 80)
		self.connect(self.tag, QtCore.SIGNAL('clicked()'), self.selectTagPic)
		
		self.tag = QtGui.QPushButton(u'功能展示图片', self)
		self.tag.setGeometry(250, 150, 300, 80)
		self.connect(self.tag, QtCore.SIGNAL('clicked()'), self.selectFunPic)
		
		self.tag = QtGui.QPushButton(u'添加标记脚本', self)
		self.tag.setGeometry(250, 250, 300, 80)
		self.connect(self.tag, QtCore.SIGNAL('clicked()'), self.selectTagBin)
		
		self.tag = QtGui.QPushButton(u'生成zip资源包', self)
		self.tag.setGeometry(250, 350, 300, 80)
		self.connect(self.tag, QtCore.SIGNAL('clicked()'), self.selectTagBin)
		
	def selectTagPic(self):
		filename = QtGui.QFileDialog.getOpenFileNames(self, 'Open file', './res/*jpg')
		#self.textEdit.setText(filename)
		cnt = 0;
		for i in filename:
			print i+str(cnt)
			strTmp = './res/Tag'+str(cnt)+'.jpg'
			print strTmp
			os.rename(i,strTmp)
			cnt = cnt+1
			img = cv2.imread(strTmp)  
			cv2.imshow("Image", img)  
		else:
			print "for end"
			
	def selectFunPic(self):
		filename = QtGui.QFileDialog.getOpenFileNames(self, 'Open file', './res/*jpg')
		#self.textEdit.setText(filename)
		cnt = 0;
		for i in filename:
			#print i+str(cnt)
			strTmp = './res/Fun'+str(cnt)+'.jpg'
			print strTmp
			os.rename(i,strTmp)
			cnt = cnt+1
		else:
			print "for end"
	
	def selectTagBin(self):
		filename = QtGui.QFileDialog.getOpenFileNames(self, 'Open file', './res/*bin')
		#self.textEdit.setText(filename)
		cnt = 0;
		for i in filename:
			print i+str(cnt)
			strTmp = './res/Fun'+str(cnt)+'.jpg'
			print strTmp
			os.rename(i,strTmp)
			cnt = cnt+1
		else:
			print "for end"
		
app = QtGui.QApplication(sys.argv)
res = resType();
res.show()
sys.exit(app.exec_())